(function (aopc) {
    aopc.addExpandPage(832, function (get) {
        const Common = get('UtilsCommon', 'Common');
        const Bridge = get('UtilsCommon', 'Bridge');

        return {
            expandInit() {
                this.container_view = this.getProperty('container_view');
                this.vote_result_view = this.getProperty('vote_result_view');
                this.score_result_view = this.getProperty('score_result_view');
                this.sign_result_view = this.getProperty('sign_result_view');
                this.title_text = this.getProperty('title_text');
                this.default_title = Common.clone(this.title_text);
                this.defaultBackgroundImage = this.container_view.style.backgroundImage;
                this.defaultBackgroundImage1 = this.defaultBackgroundImage;
                this.title_text = this.getTitleProperty();
                this.container_view.properties = [this.title_text];
                this.center_view = this.getProperty('center_view');
                this.meeting_title = this.getViewProperty(this.center_view, 'meeting_title');
                this.files_property = this.getViewProperty(this.center_view, 'Files');

                this.receiveFunctions.voteToBigScreen = this.voteToBigScreen.bind(this);
                this.receiveFunctions.closeVoteToBigScreen = this.closeToBigScreen.bind(this);

                this.receiveFunctions.scoreToBigScreen = this.scoreToBigScreen.bind(this);
                this.receiveFunctions.closeScoreToBigScreen = this.closeToBigScreen.bind(this);

                this.receiveFunctions.countToBigScreen = this.countToBigScreen.bind(this);
                this.receiveFunctions.closeCountBigScreen = this.closeToBigScreen.bind(this);
                this.receiveFunctions.refreshBigScreen = this.refreshBigScreen.bind(this);
                this.receiveFunctions.exitBigScreen = this.exitBigScreen.bind(this);
                this.receiveFunctions.setCacheVideos = this.setCacheVideos.bind(this);
                this.isBigScreen = true;

                Bridge.setReceiveFunction('downloadProgress', (data) => this.downloadProgress(data.Files));
            },
            setCacheVideos(data) {
                this.pageData.MeetingId = data.MeetingId;
                this.center_view.reLoad();
                this.setValue(this.meeting_title, data.Title);

                if (data.isShowProgress) {
                    this.setFilesVisible(true);
                }
            },
            setFilesVisible(v) {
                this.center_view.properties[0].setIsVisible(v);
                this.container_view.setIsVisible(!v);
            },
            expandGetMeetingSubjectData({ entityData }) {
                entityData.queryString = "IsList=true";
                return entityData;
            },
            expandSubjectDataLoad({ data }) {
                const { Subjects } = data;
                if (Subjects) {
                    const files = [];
                    this.fileObject = {};
                    Subjects.forEach(s => {
                        if (s.Files) {
                            s.Files.forEach(f => {
                                if (this.visitUser.VideoFormat && this.visitUser.VideoFormat.toLowerCase().indexOf(f.FileType.substring(1).toLowerCase()) >= 0) {
                                    files.push(f);
                                    this.fileObject[f.FileId] = f;
                                }
                            });
                        }
                    });
                    if (files.length > 0) {
                        Bridge.jsToNative('downloadFiles', { Files: files, MeetingId: this.pageData.MeetingId });
                    }
                    this.setValue(this.files_property, files);
                }
            },
            exitBigScreen(data) {
                if (data.userId === this.currentUserId || data.isExit) {
                    this.currentUserId = null;
                    this.container_view.style.backgroundImage = data.isExit ? this.defaultBackgroundImage1 : this.defaultBackgroundImage;
                    this.container_view.properties = [this.getDefaultTitleProperty()];
                    this.container_view.refresh();
                }
                this.setFilesVisible(false);
            },
            refreshBigScreen(data) {
                this.currentUserId = data.userId;
                if (data.Content) {
                    this.title_text.spanStyle.color = data.FontColor;
                    this.title_text.className = '';
                }
                else this.title_text.className = 'divTitle2';
                this.setValue(this.title_text, data.Title || data.Content);
                this.title_text.refresh();
                this.container_view.style.backgroundImage = `url(${data.BackImageUrl})`;
                this.defaultBackgroundImage = data.BackImageUrl;
                this.container_view.refresh();
                this.setFilesVisible(false);
            },
            setValue(p, v) {
                p.value = v;
                p.setValue && p.setValue(v);
            },
            getTitleProperty() {
                const p = Common.clone(this.title_text);
                p.id = Common.createGuid();
                p.isVisible = true;
                this.title_text = p;
                return p
            },
            getDefaultTitleProperty() {
                const p = Common.clone(this.default_title);
                p.id = Common.createGuid();
                p.isVisible = true;
                this.title_text = p;
                return p
            },
            closeToBigScreen() {
                this.container_view.properties = [this.getTitleProperty()];
                this.container_view.refresh();
                this.setFilesVisible(false);
            },
            voteToBigScreen({ ids, userId }) {
                this.currentUserId = userId;
                const view = Common.clone(this.vote_result_view);
                view.id = Common.createGuid();
                view.isVisible = true;

                const { serviceName, actionName } = view.serviceInterface;

                const ids2 = [];
                const parameters = [];
                ids.forEach((id, i) => {
                    ids2.push(`@VoteId${i}`);
                    parameters.push(`@VoteId${i}=${id}`);
                });

                const payload = { pathQuery: `&$filter=VoteId in (${ids2.join(',')})&${parameters.join("&")}` }

                this.dispatchAction(serviceName, actionName, payload).then(res => {
                    if (res.isSuccess !== false) {
                        this.setBarChartData(view.properties[0], res);
                        this.container_view.properties = [view];
                        this.container_view.refresh();
                        this.setFilesVisible(false);
                    }
                });
            },
            setBarChartData(property, dataList) {
                property.legendNames = [];

                property.xName = 'Title';

                const list = [];

                const obj = {};

                dataList.forEach(item => {
                    if (!obj[item.Title]) {
                        obj[item.Title] = {};
                        const items = item.VoteItems.replaceAll('；', ';').split(';');
                        items.forEach(item2 => {
                            obj[item.Title][item2] = 0;
                            if (!property.legendNames.includes(item2)) property.legendNames.push(item2);
                        });
                    }
                    obj[item.Title][item.VoteItem] = item.VoteCount;
                });

                for (const key in obj) {
                    const vote = obj[key];
                    const data = {};
                    data.Title = key;

                    property.legendNames.forEach(item => {
                        data[item] = vote[item];
                    });

                    list.push(data);
                }

                property.yNames = property.legendNames;
                property.dataList = list;

                if (list.length == 0) {
                    this.alert('暂无数据');
                }
            },
            scoreToBigScreen({ ids, userId }) {
                this.currentUserId = userId;
                const view = Common.clone(this.score_result_view);
                view.id = Common.createGuid();
                view.isVisible = true;

                const { serviceName, actionName } = view.serviceInterface;

                const ids2 = [];
                const parameters = [];
                ids.forEach((id, i) => {
                    ids2.push(`@ScoreId${i}`);
                    parameters.push(`@ScoreId${i}=${id}`);
                });

                const payload = { pathQuery: `&$filter=ScoreId in (${ids2.join(',')})&${parameters.join("&")}` }

                this.dispatchAction(serviceName, actionName, payload).then(res => {
                    if (res.isSuccess !== false) {
                        this.setBarChartData2(view.properties[0], res);
                        this.container_view.properties = [view];
                        this.container_view.refresh();
                        this.setFilesVisible(false);
                    }
                });
            },
            setBarChartData2(property, dataList) {
                property.legendNames = ["最小分", "最高分", "平均分", "评分人数"];
                property.xName = 'Title';
                property.yNames = "MinScore,MaxScore,AvgScore,ScoreCount";
                property.dataList = dataList;
            },
            countToBigScreen({ MeetingId, MeetingRoomId, userId }) {
                this.currentUserId = userId;
                const view = Common.clone(this.sign_result_view);
                view.id = Common.createGuid();
                view.isVisible = true;

                const { serviceName, actionName } = view.serviceInterface;


                const payload = { pathQuery: `(${MeetingId})?MeetingRoomId=${MeetingRoomId}` }

                this.dispatchAction(serviceName, actionName, payload).then(res => {
                    if (res.isSuccess !== false) {
                        this.setBarChartData3(view.properties[0], res);
                        this.container_view.properties = [view];
                        this.container_view.refresh();
                        this.setFilesVisible(false);
                    }
                });
            },
            setBarChartData3(property, data) {
                property.legendNames = ["应签人数", "已签人数", "未签人数"];
                property.title = data.Title
                property.pieName = 'sign count';
                const list = [{
                    value: data.UserCount,
                    name: '应签人数',
                },
                {
                    value: data.SignCount,
                    name: '已签人数',
                },
                {
                    value: data.UnSignCount,
                    name: '未签人数',
                }];
                property.dataList = list;
            },
            setFileRow({ data, view }) {
                const file_icon = this.getViewProperty(view, 'file_icon');
                if (file_icon) {
                    file_icon.imgUrl = this.getFileIcon(data);
                };
                const p = this.getViewProperty(view, 'DownloadProgress');
                if (p) {
                    p.spanId = "span_" + data.FileId;
                    if (data.Percentage === 100) {
                        p.spanStyle.color = '#2a2a2a';
                    }
                }
                const p2 = this.getViewProperty(view, 'unite_view');
                if (p2) {
                    p2.isVisible = this.isHost;
                    this.unite_views[data.FileId] = p2;
                }
            },
            getFileIcon(data) {
                const t = data.FileType.toLowerCase();
                const vt = '.mp4,.mov,.avi,.mkv,.rmvb';
                const it = '.jpg,.jpeg,.png,.gif,.svg';
                if (t === '.doc' || t === '.docx') return "/images/yxinmt_h5/25080313563175553.png";
                else if (t === '.xls' || t === '.xlsx') return "/images/yxinmt_h5/25080313565026910.png";
                else if (t === '.ppt' || t === '.pptx') return "/images/yxinmt_h5/25080313564674186.png";
                else if (t === '.pdf') return "/images/yxinmt_h5/25080313563543435.png";
                else if (vt.indexOf(t) >= 0) return '/images/yxinmt_h5/25080521052203829.png';
                else if (it.indexOf(t) >= 0) return '/images/yxinmt_h5/25080521052598726.png';
                else return "/images/yxinmt_h5/25080521052936371.png";
            },
            downloadProgress(files) {
                for (let i = 0; i < files.length; i++) {
                    const file = files[i];
                    const ele = document.getElementById("span_" + file.FileId);
                    if (ele) {
                        ele.innerHTML = file.DownloadProgress || '';
                        if (file.Percentage === 100) {
                            ele.style.color = '#2a2a2a';
                        }
                    }
                    else {
                        const file2 = this.fileObject[file.FileId];
                        if (file2) {
                            file2.DownloadProgress = file.DownloadProgress;
                            file2.Percentage = file.Percentage;
                        }
                    }
                }
            }
        }
    });
})(window.aopc);